//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "EnergySwap.h"
using namespace Cephei::QL::Experimental::Commodities;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Experimental/Commodities/CommodityType.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Experimental/Commodities/PricingPeriod.h>
#include <gen/QL/Experimental/Commodities/Quantity.h>
#include <gen/QL/Experimental/Commodities/PricingError.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Experimental/Commodities/EnergyCommodity.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Commodities::CEnergySwap::CEnergySwap (boost::shared_ptr<QuantLib::EnergySwap>& childNative, Object^ owner) : CEnergyCommodity(CEnergySwap::typeid)
{
#ifdef HANDLE
	_phEnergySwap = NULL;
#endif
	_ppEnergySwap = &childNative;
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergySwap));
}
Cephei::QL::Experimental::Commodities::CEnergySwap::CEnergySwap (QuantLib::EnergySwap& childNative, Object^ owner) : CEnergyCommodity(CEnergySwap::typeid)
{
#ifdef HANDLE
	_phEnergySwap = NULL;
#endif
	_ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (&childNative);
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergySwap));
    _EnergySwapOwner = owner;
    _EnergyCommodityOwner = owner;
}

Cephei::QL::Experimental::Commodities::CEnergySwap::CEnergySwap (CEnergySwap^ copy) : CEnergyCommodity(CEnergySwap::typeid)
{
#ifdef HANDLE
	_phEnergySwap = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (copy->GetShared());
        _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergySwap));
    }
}
Cephei::QL::Experimental::Commodities::CEnergySwap::CEnergySwap (PLATFORM::Type^ t) : CEnergyCommodity(CEnergySwap::typeid)
{
#ifdef HANDLE
	_phEnergySwap = NULL;
#endif
	if (!t->IsSubclassOf(CEnergySwap::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Commodities::CEnergySwap::CEnergySwap (QuantLib::Handle<QuantLib::EnergySwap>& childNative, Object^ owner)  : CEnergyCommodity(CEnergySwap::typeid)
{
	_phEnergySwap = &childNative;
	_ppEnergySwap = &static_cast<boost::shared_ptr<QuantLib::EnergySwap>>(childNative.currentLink());
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergySwap));
    _EnergySwapOwner = owner;
}
Cephei::QL::Experimental::Commodities::CEnergySwap::CEnergySwap (QuantLib::Handle<QuantLib::EnergySwap> childNative)  : CEnergyCommodity(CEnergySwap::typeid)
{
	_phEnergySwap = &childNative;
	_ppEnergySwap = &static_cast<boost::shared_ptr<QuantLib::EnergySwap>>(childNative.currentLink());
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergySwap));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Commodities::CEnergySwap::CEnergySwap (QuantLib::EnergySwap childNative)  : CEnergyCommodity(CEnergySwap::typeid)
{
#ifdef HANDLE
	_phEnergySwap = NULL;
#endif
	_ppEnergySwap = new boost::shared_ptr<QuantLib::EnergySwap> (new QuantLib::EnergySwap (childNative));
    _ppEnergyCommodity = new boost::shared_ptr<QuantLib::EnergyCommodity> (boost::dynamic_pointer_cast<QuantLib::EnergyCommodity> (*_ppEnergySwap));
}
#endif

Cephei::QL::Experimental::Commodities::CEnergySwap::~CEnergySwap ()
{
    if (_ppEnergySwap != NULL)
    {
	    delete _ppEnergySwap;
        _ppEnergySwap = NULL;
    }
}
Cephei::QL::Experimental::Commodities::CEnergySwap::!CEnergySwap ()
{
    if (_ppEnergySwap != NULL)
    {
	    delete _ppEnergySwap;
    }
}
QuantLib::EnergySwap& Cephei::QL::Experimental::Commodities::CEnergySwap::GetReference ()
{
    if (_ppEnergySwap == NULL) throw REFNEW NativeNullException ();
	return **_ppEnergySwap;
}
boost::shared_ptr<QuantLib::EnergySwap>& Cephei::QL::Experimental::Commodities::CEnergySwap::GetShared ()
{
    if (_ppEnergySwap == NULL) throw REFNEW NativeNullException ();
	return *_ppEnergySwap;
}
QuantLib::EnergySwap* Cephei::QL::Experimental::Commodities::CEnergySwap::GetPointer ()
{
    if (_ppEnergySwap == NULL) throw REFNEW NativeNullException ();
	return &**_ppEnergySwap;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::EnergySwap>& Cephei::QL::Experimental::Commodities::CEnergySwap::GetHandle ()
{
	if (_phEnergySwap == NULL)
	{
		_phEnergySwap = new Handle<QuantLib::EnergySwap> (*_ppEnergySwap);
	}
	return *_phEnergySwap;
}
#endif
bool Cephei::QL::Experimental::Commodities::CEnergySwap::HasNative () 
{
	return (_ppEnergySwap != NULL);
}

Cephei::QL::Times::ICalendar^ Cephei::QL::Experimental::Commodities::CEnergySwap::Calendar::get ()
{
    try
    {
    	QuantLib::Calendar& _rv = (QuantLib::Calendar&)(*_ppEnergySwap)->calendar ( );   
        Cephei::QL::Times::CCalendar^ _nrv = REFNEW Cephei::QL::Times::CCalendar (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::ICommodityType^ Cephei::QL::Experimental::Commodities::CEnergySwap::CommodityType::get ()
{
    try
    {
    	QuantLib::CommodityType& _rv = (QuantLib::CommodityType&)(*_ppEnergySwap)->commodityType ( );   
        Cephei::QL::Experimental::Commodities::CCommodityType^ _nrv = REFNEW Cephei::QL::Experimental::Commodities::CCommodityType (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Experimental::Commodities::CEnergySwap::IsExpired::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppEnergySwap)->isExpired ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::ICurrency^ Cephei::QL::Experimental::Commodities::CEnergySwap::PayCurrency::get ()
{
    try
    {
    	QuantLib::Currency& _rv = (QuantLib::Currency&)(*_ppEnergySwap)->payCurrency ( );   
        Cephei::QL::CCurrency^ _nrv = REFNEW Cephei::QL::CCurrency (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::Experimental::Commodities::IPricingPeriod^>^ Cephei::QL::Experimental::Commodities::CEnergySwap::PricingPeriods::get ()
{
    try
    {
    	std::vector<boost::shared_ptr<QuantLib::PricingPeriod> >& _rv = (std::vector<boost::shared_ptr<QuantLib::PricingPeriod> >&)(*_ppEnergySwap)->pricingPeriods ( );   
        CoVector<Cephei::QL::Experimental::Commodities::IPricingPeriod^>^ _nrv = REFNEW CoVector<Cephei::QL::Experimental::Commodities::IPricingPeriod^>(REFNEW CPricingPeriodVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::IQuantity^ Cephei::QL::Experimental::Commodities::CEnergySwap::Quantity::get ()
{
    try
    {
    	QuantLib::Quantity _rv = (QuantLib::Quantity)(*_ppEnergySwap)->quantity ( );   
        Cephei::QL::Experimental::Commodities::CQuantity^ _nrv = REFNEW Cephei::QL::Experimental::Commodities::CQuantity (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::ICurrency^ Cephei::QL::Experimental::Commodities::CEnergySwap::ReceiveCurrency::get ()
{
    try
    {
    	QuantLib::Currency& _rv = (QuantLib::Currency&)(*_ppEnergySwap)->receiveCurrency ( );   
        Cephei::QL::CCurrency^ _nrv = REFNEW Cephei::QL::CCurrency (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

